/*
 * Created by JFormDesigner on Thu May 19 20:36:24 CST 2022
 */

package jw3.c2.view;

import java.awt.event.*;

import jw3.c2.controller.AdministratorController;

import java.awt.*;
import javax.swing.*;

/**
 * @author Brainrain
 */
public class Login extends JFrame {
    public Login() {
        initComponents();
        setLocation(500,300);
        setSize(800,600);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setVisible(true);
    }

    private void button1MouseClicked(MouseEvent e) {
        // TODO add your code here
        String user=textField1.getText();
        String pwd=new String(passwordField1.getPassword());
        if (!user.equals("") && !pwd.equals("")){
        if (AdministratorController.login(user,pwd)){
            JOptionPane.showMessageDialog(null,"登陆成功！");
            Home h=new Home();
            setVisible(false);
        }else {
            JOptionPane.showMessageDialog(null,"账号或密码错误！");
        }
        }else {
            JOptionPane.showMessageDialog(null,"账号或密码不能为空！");
        }
    }

    private void label3MouseClicked(MouseEvent e) {
        // TODO add your code here
        Login1 l1=new Login1();
        setVisible(false);
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        label1 = new JLabel();
        textField1 = new JTextField();
        label2 = new JLabel();
        passwordField1 = new JPasswordField();
        button1 = new JButton();
        label3 = new JLabel();
        label4 = new JLabel();

        //======== this ========
        setTitle("\u767b\u5f55\u754c\u9762");
        setIconImage(null);
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u8d26\u53f7\uff1a");
        contentPane.add(label1);
        label1.setBounds(new Rectangle(new Point(250, 155), label1.getPreferredSize()));
        contentPane.add(textField1);
        textField1.setBounds(305, 148, 140, 30);

        //---- label2 ----
        label2.setText("\u5bc6\u7801\uff1a");
        contentPane.add(label2);
        label2.setBounds(new Rectangle(new Point(250, 215), label2.getPreferredSize()));
        contentPane.add(passwordField1);
        passwordField1.setBounds(305, 208, 140, 30);

        //---- button1 ----
        button1.setText("\u767b\u5f55");
        button1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button1MouseClicked(e);
            }
        });
        contentPane.add(button1);
        button1.setBounds(new Rectangle(new Point(336, 275), button1.getPreferredSize()));

        //---- label3 ----
        label3.setText("\u5fd8\u8bb0\u5bc6\u7801?");
        label3.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                label3MouseClicked(e);
            }
        });
        contentPane.add(label3);
        label3.setBounds(new Rectangle(new Point(445, 282), label3.getPreferredSize()));

        //---- label4 ----
        label4.setIcon(new ImageIcon("C:\\Users\\\u5c0f\u6797\\Desktop\\L.jpg"));
        contentPane.add(label4);
        label4.setBounds(new Rectangle(new Point(-415, -5), label4.getPreferredSize()));

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel label1;
    private JTextField textField1;
    private JLabel label2;
    private JPasswordField passwordField1;
    private JButton button1;
    private JLabel label3;
    private JLabel label4;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
